package com.fjec.im.controller;

import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.fjec.common.annotation.Json;
import com.fjec.common.protocol.JsonResult;
import com.fjec.im.service.IBizUserMessageService;
import com.fjec.im.service.ICommonService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import javax.annotation.Resource;
import java.util.Map;

/**
 * <p>
 * 013.用户留言表 前端控制器
 * </p>
 *
 * @author admin
 * @since 2020-09-23
 */
@RestController
@RequestMapping("/")
public class BizUserMessageController {

    @Resource
    private IBizUserMessageService service;

    @Autowired
    private ICommonService commonService;

    /**
     * 获取指定会话的信息列表
     *
     * @param page
     * @param convId
     * @return
     */
    @GetMapping("/y/im/msg/list")
    public JsonResult getList(Page page, Long convId) {
        return service.getList(page, convId);
    }

    /**
     * 发送消息
     *
     * @param convId  会话Id
     * @param content 消息内容
     * @return
     */
    @PostMapping("/y/im/msg/send")
    public JsonResult sendMsg(Long convId, Long toId, String content) {
        return service.save(convId, toId, content);
    }

    /**
     * 获取未读消息数量
     *
     * @return
     * @throws Exception
     */
    @Deprecated
    @GetMapping("/y/im/unread/num")
    public JsonResult getUnReadNum() throws Exception {
        return JsonResult.success()
                .data(service.getUnReadNum())
                .build();
    }

    /**
     * 获取未读消息数量
     *
     * @param userId
     * @return
     */
    @GetMapping("/im/unread/num")
    public Map<String, Object> getUnReadNum(Long userId) {
        return service.getUnReadNum(userId);
    }

    @PostMapping("/test/msg")
    public String testMsg() {
//        commonService.sendNewOrder("13654991498");
        commonService.sendRemindDeliver("13654991498");
        return "success";
    }
}
